<?php

/**
 * sfWidgetFormDoctrineChoice represents a choice widget for a model.
 *
 * @package    symfony
 * @subpackage doctrine
 * @version    SVN: $Id: sfWidgetFormInputCurrency.class.php 29679 2010-05-30 14:46:03Z Kris.Wallsmith $
 */
class sfWidgetFormInputCurrency extends sfWidgetFormInput {
	/**
	 * @see sfWidget
	 */
	public function __construct($options = array(), $attributes = array()) {
		parent::__construct ( $options, $attributes );
	}
	
	
	/**
	 * (non-PHPdoc)
	 * @see sfWidgetFormInput::configure()
	 */
	protected function configure($options = array(), $attributes = array()) {
		$this->addOption ( 'decimal', 0 );
		$this->addOption ( 'unit', 'VNĐ' );
		parent::configure ( $options, $attributes );
	}
	
	public function render($name, $value = null, $attributes = array(), $errors = array()) {
		if(!$errors && $value){
			$value = @number_format ( $value, $this->getOption ( 'decimal' ), ',', ' ' );
		}
		return $this->renderTag ( 'input', array_merge ( array ('type' => $this->getOption ( 'type' ), 
			'name' => $name, 
			'value' => $value), 
			$attributes ) ) . " " . $this->getOption ( 'unit' );
	}
}